package com.xysd.express.adapter;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.annotation.LayoutRes;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.xysd.express.R;
import com.xysd.express.bean.HomePageObj;
import com.xysd.express.util.TextUtil;

/**
 * Created by donghui on 2017/11/20.
 */

public class HomeOrderAdpter extends BaseQuickAdapter<HomePageObj.HomeOrder,BaseViewHolder> {
    Context context;

    public HomeOrderAdpter(@LayoutRes int layoutResId, Context context) {
        super(layoutResId);
        this.context = context;
    }

    @Override
    protected void convert(BaseViewHolder helper, HomePageObj.HomeOrder item) {
        TextView adds_send=helper.getView(R.id.adds_send);
        TextView adds_receive=helper.getView(R.id.adds_receive);
        adds_send.setText(item.OrderProfile.ShipAddress);
        adds_receive.setText(item.OrderProfile.ReceiveAddress);

        ImageView type_img=helper.getView(R.id.type_img);
        type_img.setImageLevel(1);

        Drawable sendDrawable= context.getResources().getDrawable(R.mipmap.order_send);
        Drawable receiveDrawable= context.getResources().getDrawable(R.mipmap.order_receive);
        if (item.SourceType==1){//物流
            sendDrawable= context.getResources().getDrawable(R.mipmap.order_send);
            receiveDrawable= context.getResources().getDrawable(R.mipmap.order_receive);
        }
        if (item.SourceType==2){//快递
            sendDrawable= context.getResources().getDrawable(R.mipmap.order_send);
            receiveDrawable= context.getResources().getDrawable(R.mipmap.order_qu);
        }
        if (item.SourceType==3){//跑腿
            sendDrawable= context.getResources().getDrawable(R.mipmap.order_send);
            receiveDrawable= context.getResources().getDrawable(R.mipmap.order_receive);
        }
        if (item.SourceType==4){//代购
            sendDrawable= context.getResources().getDrawable(R.mipmap.order_buy);
            receiveDrawable= context.getResources().getDrawable(R.mipmap.order_receive);
        }
        sendDrawable.setBounds(0,0,sendDrawable.getMinimumWidth(),sendDrawable.getMinimumHeight());
        receiveDrawable.setBounds(0,0,receiveDrawable.getMinimumWidth(),receiveDrawable.getMinimumHeight());
        adds_send.setCompoundDrawables(sendDrawable,null,null,null);
        adds_receive.setCompoundDrawables(receiveDrawable,null,null,null);

        helper.setText(R.id.status_tv,item.StatusDescription);
        helper.setText(R.id.time_tv,item.OperateTime);

        //设置金额
        TextView money_tv=helper.getView(R.id.money_tv);
        new TextUtil().setTextColor(money_tv,"费用：￥"+item.OrderAmount,3,("费用：￥"+item.OrderAmount).length(),"#fa0d09");

        //监听查看详情
        helper.addOnClickListener(R.id.details_tv);
    }
}
